import 'package:yzb_flutter/model/banner_entity.dart';
import 'package:yzb_flutter/model/login_info_entity.dart';
import 'package:yzb_flutter/utils/api.dart';
import 'package:yzb_flutter/utils/net_utils.dart';
import 'package:yzb_flutter/utils/utils.dart';

class DataUtil{
  static Future<LoginInfoEntity> doLogin(Map<String,dynamic> params) async {
    var response = await NetUtil.getIns().post(Api.loginUrl, params);
    try{
      LoginInfoEntity loginInfo = LoginInfoEntity.fromJson(response['data']);
      return loginInfo;
    }catch(err){
      Utils.showToast(response['errorMsg'],error: true);
      return null;
    }
  }


  static Future<LoginInfoEntity> doRegist(Map<String,dynamic> params) async {
    var response = await NetUtil.getIns().post(Api.registUrl, params);
    try{
      LoginInfoEntity loginInfo = LoginInfoEntity.fromJson(response['data']);
      return loginInfo;
    }catch(err){
      Utils.showToast(response['errorMsg'],error: true);
      return null;
    }
  }

  static Future getBanner() async {
    var response = await NetUtil.getIns().get(Api.bannerUrl,null);
    try{
      List<BannerEntity> bannerList = [];
      for(Map<String,dynamic> json in response["data"]){
          bannerList.add(BannerEntity.fromJson(json));
      }
      return bannerList;
    }catch(err){
      Utils.showToast(response['errorMsg'],error: true);
      return null;
    }
  }
}